﻿using WebApiClientCore;

namespace BPM.Web.Shared;

/// <summary>
/// Blazor客户端HTTP请求Token拦截器
/// </summary>
public class TokenInterceptor : ITokenInterceptor
{
    /// <summary>
    /// 在HTTP请求发送前
    /// </summary>
    public event EventHandler<ApiRequestContext?>? BeforeSend;

    /// <summary>
    /// 在收到HTTP请求的响应后（包括它没有成功）。
    /// </summary>
    public event EventHandler<ApiResponseContext?>? AfterSend;

    public Guid? Id { get; set; }

    public TokenInterceptor()
    {
        Id = Guid.NewGuid();
    }

    public void InvokeBeforeSend(ApiRequestContext? args) => BeforeSend?.Invoke(this, args);

    public void InvokeAfterSend(ApiResponseContext? args) => AfterSend?.Invoke(this, args);
}

